#include <iostream>
#include<windows.h>
#include<vector>
#include<ctime>
#include"Date.h"
#include"UI.h"
using namespace std;

int main()
{
	UI ui;
	ui.showtitle();
	Date solar;
	Date solar2;
	Lunar lunar;
	int tday;
	int year;
	int op;
	int choice;
	vector<pair<string, Date>>JieQi;
	do
	{
		ui.showmenu();
		cin >> choice;
		if(choice==9)
			break;
		while (choice < 1 || choice>9)
		{
			cout << "输入错误！请重新输入1-9的数字：" ;
			cin >> choice;
		}
		switch (choice)
		{
		case 1:
			cout<<"请输入公历日期：";
			cin >> solar.year >> solar.month >> solar.day;
			while(!validatesolar(solar.year, solar.month, solar.day))
			{
				cout << "输入日期错误！请重新输入：" ;
				cin >> solar.year >> solar.month >> solar.day;
			}
			lunar=Solar2Lunar(solar);
			setColor(RED, WHITE_BACKGROUND);
			cout<<"\t\t农历"<<lunar.lyear<<"年"<<lunar.lmonth<<"月"<<lunar.lday<<"日"<<endl;
			week(solar.year, solar.month, solar.day);
			tiangan(solar);
			isJieqi(solar);
			JieQi = calculateJieqi(solar.year);
			cout<<"当月的节气日期："<<endl;
			for (int i = 0; i < JieQi.size(); i++)
			{
				if (JieQi[i].second.month == solar.month)
					cout << "\t\t" << JieQi[i].first << ":" << JieQi[i].second.month << "月" << JieQi[i].second.day << "日" << endl;
				if(JieQi[i].second.month==solar.month+1)
					break;
			}
			setColor(BLACK, WHITE_BACKGROUND);
			showmonth(solar.year, solar.month);
			break;
		case 2:
			cout<<"请输入农历日期：";
			cin >> lunar.lyear >> lunar.lmonth >> lunar.lday;
			while (!validatelunar(lunar.lyear, lunar.lmonth, lunar.lday))
			{
				cout << "输入日期错误！请重新输入：" ;
				cin >> lunar.lyear >> lunar.lmonth >> lunar.lday;
			}
			setColor(RED, WHITE_BACKGROUND);
			solar=Lunar2Solar(lunar);
			cout<<"\t\t公历"<<solar.year<<"年"<<solar.month<<"月"<<solar.day<<"日"<<endl;
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		case 3:
			cout<<"请输入公历年月：";
			cin >> solar.year >> solar.month;
			while (cin.peek() != EOF && cin.peek() != '\n')
			{
				cout << "输入参数过多！请重新输入：";
				cin.clear();
				cin.ignore(10000, '\n');
				cin >> solar.year >> solar.month;
				while (solar.month < 1 || solar.month>12)
				{
					cout << "输入数据错误！请重新输入：";
					cin >> solar.year >> solar.month;
				}
			}
			
			showmonth(solar.year, solar.month);
			break;
		case 4:
			cout<<"请输入日期：";
			cin >> solar.year >> solar.month >> solar.day; 
			while (!validatesolar(solar.year, solar.month, solar.day))
			{
				cout << "输入日期错误！请重新输入：" ;
				cin >> solar.year >> solar.month >> solar.day;
			}
			setColor(RED, WHITE_BACKGROUND);
			day2now(solar);
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		case 5:
			cout<<"请输入天数：";
			cin>>tday;
			while (cin.peek() != EOF && cin.peek() != '\n')
			{
				cout << "输入参数过多！请重新输入：";
				cin.clear();
				cin.ignore(10000, '\n');
				cin >> tday;
			}
			setColor(RED, WHITE_BACKGROUND);
			now2day(tday);
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		case 6:
			cout<<"请输入两个公历日期：";
			cin >> solar.year >> solar.month >> solar.day;
			cin >> solar2.year >> solar2.month >> solar2.day;
			while (!validatesolar(solar.year, solar.month, solar.day) ||!validatesolar(solar2.year, solar2.month, solar2.day))
			{
				cout << "输入日期错误！请重新输入：" ;
				cin >> solar.year >> solar.month >> solar.day;
				cin >> solar2.year >> solar2.month >> solar2.day;
			}
			setColor(RED, WHITE_BACKGROUND);
			diffday(solar,solar2);
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		case 7:
			cout << "请输入年份：";
			cin >> year;
			setColor(RED, WHITE_BACKGROUND);
			jieqi(year);
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		case 8:
			cout << "请输入选项，1显示公历节日，2显示农历节日：";
			cin >> op;
			setColor(RED, WHITE_BACKGROUND);
			showfestival(op);
			setColor(BLACK, WHITE_BACKGROUND);
			break;
		default:
			cout<<"输入错误！请重新输入"<<endl;
		}
	}while(1);
		
}